﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Abp.Domain.Repositories;
using Abp.Domain.Services;
using Abp.UI;
using FwProject.Core.AppVersion;
using FwProject.ShoppingMall.Com;
using FwProject.ShoppingMall.EventAdvertising;

namespace FwProject.Manager
{
    public class ShopOrderCouponManager : IDomainService
    {
        private readonly IRepository<ShopOrderCoupon, Guid> _shopOrderCouponRepository;
        private readonly IRepository<ShopUserCoupon, Guid> _shopUserCouponRepository;
        private readonly IRepository<ShopCar, Guid> _shopCarRepository;

        public ShopOrderCouponManager(IRepository<ShopOrderCoupon, Guid> shopOrderCouponRepository,
            IRepository<ShopCar, Guid> shopCarRepository,
            IRepository<ShopUserCoupon, Guid> shopUserCouponRepository)
        {
            _shopUserCouponRepository = shopUserCouponRepository;
            _shopOrderCouponRepository = shopOrderCouponRepository;
            _shopCarRepository = shopCarRepository;
        }
        /// <summary>
        /// 添加一个订单明细
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<Guid> CreateShopOrderCoupon(ShopOrderCoupon model)
        {
            var m= _shopUserCouponRepository.Get(model.ShopUserCouponId);
            m.UseStatus = UseStatus.Used;

            return await _shopOrderCouponRepository.InsertAndGetIdAsync(model);
           
        }
        /// <summary>
        /// 修改一个订单明细
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>

        public async Task UpdateShopOrderCoupon(ShopOrderCoupon model)
        {
            await _shopOrderCouponRepository.UpdateAsync(model);
        }

        /// <summary>
        /// 删除一个订单明细
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task DeleteShopOrderCoupon(ShopOrderCoupon model)
        {
            await _shopOrderCouponRepository.DeleteAsync(model);
        }
    }
}
